/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * tabtest.java
 *
 * Created on Jun 10, 2009, 4:47:37 PM
 */
package GeneralTesting;

/**
 *
 * @author Heather
 */
import DragBarPanelPackage.DragBarPanel;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;

public class tabtest extends javax.swing.JApplet
{

  /** Initializes the applet tabtest */
  public void init()
  {
    try
    {
      java.awt.EventQueue.invokeAndWait(new Runnable()
      {

        public void run()
        {
          initComponents();
          Component c = theTabbedPane.getTabComponentAt(0);
          if (c != null)
          {
            System.out.println("not null");
          }
          else
          {
            System.out.println("is null");
          }
          movingPanel.setSize(firstPanel.getSize());
          movingPanel.setPreferredSize(firstPanel.getPreferredSize());
          movingPanel.setBackground(Color.white);
          firstPanel.add(movingPanel);
        }
      });
    } catch (Exception ex)
    {
      ex.printStackTrace();
    }
  }

  /** This method is called from within the init() method to
   * initialize the form.
   * WARNING: Do NOT modify this code. The content of this method is
   * always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    theTabbedPane = new javax.swing.JTabbedPane();
    firstPanel = new javax.swing.JPanel();
    jButton1 = new javax.swing.JButton();
    jButton2 = new javax.swing.JButton();

    getContentPane().setLayout(null);

    theTabbedPane.addChangeListener(new javax.swing.event.ChangeListener() {
      public void stateChanged(javax.swing.event.ChangeEvent evt) {
        theTabbedPaneStateChanged(evt);
      }
    });

    firstPanel.setBackground(new java.awt.Color(255, 255, 255));

    javax.swing.GroupLayout firstPanelLayout = new javax.swing.GroupLayout(firstPanel);
    firstPanel.setLayout(firstPanelLayout);
    firstPanelLayout.setHorizontalGroup(
      firstPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 335, Short.MAX_VALUE)
    );
    firstPanelLayout.setVerticalGroup(
      firstPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGap(0, 282, Short.MAX_VALUE)
    );

    theTabbedPane.addTab("tab1", firstPanel);

    getContentPane().add(theTabbedPane);
    theTabbedPane.setBounds(10, 20, 340, 310);

    jButton1.setText("add tab");
    jButton1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton1ActionPerformed(evt);
      }
    });
    getContentPane().add(jButton1);
    jButton1.setBounds(10, 340, 160, 100);

    jButton2.setText("remove a tab");
    jButton2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jButton2ActionPerformed(evt);
      }
    });
    getContentPane().add(jButton2);
    jButton2.setBounds(180, 340, 170, 100);
  }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton1ActionPerformed
    {//GEN-HEADEREND:event_jButton1ActionPerformed


      JPanel aNewPanel = new JPanel();
      aNewPanel.setSize(firstPanel.getSize());
      aNewPanel.setPreferredSize(firstPanel.getPreferredSize());
      aNewPanel.setBackground(Color.white);
      aNewPanel.setLayout(null);
      //JLabel bleep = new JLabel("bleeeeeep");
      //bleep.setSize(100, 100);
      //bleep.setPreferredSize(new Dimension(100, 100));
      //aNewPanel.add(bleep);
      //aNewPanel.add(movingPanel);
      
      JScrollPane scrollP = new JScrollPane();
      scrollP.setBackground(Color.red);
      scrollP.setSize(firstPanel.getSize());
      scrollP.setPreferredSize(firstPanel.getSize());
      aNewPanel.add(scrollP);

      DragBarPanel dbp = new DragBarPanel(5);
      dbp.setSize(firstPanel.getSize());
      dbp.setPreferredSize(firstPanel.getSize());
      System.out.println(dbp.getSize());
      scrollP.add(dbp);
      scrollP.setViewportView(dbp);
      //aNewPanel.add(dbp);

      dbp.setLocation(0, 0);

      theTabbedPane.addTab("blah blah", aNewPanel);
      theTabbedPane.updateUI();

      //firstPanel.add(dbp);

      //theOnlyPane.addTab("blah blah", firstPanel);
      //JPanel c = (JPanel) theOnlyPane.getSelectedComponent();
      //c.add(movingPanel);


    //theOnlyPane.addTab("blah blah0", dbp);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void theTabbedPaneStateChanged(javax.swing.event.ChangeEvent evt)//GEN-FIRST:event_theTabbedPaneStateChanged
    {//GEN-HEADEREND:event_theTabbedPaneStateChanged
      // TODO add your handling code here:

      //JPanel c = (JPanel)theOnlyPane.getSelectedComponent();
      //c.add(movingPanel);
      //movingPanel.setLocation(new Point (0, 0));
      repaint();
}//GEN-LAST:event_theTabbedPaneStateChanged

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton2ActionPerformed
    {//GEN-HEADEREND:event_jButton2ActionPerformed
      // TODO add your handling code here:
      if (theTabbedPane.getTabCount() > 2)
      {
        theTabbedPane.removeTabAt(2);
        theTabbedPane.updateUI();
      }
    }//GEN-LAST:event_jButton2ActionPerformed

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JPanel firstPanel;
  private javax.swing.JButton jButton1;
  private javax.swing.JButton jButton2;
  private javax.swing.JTabbedPane theTabbedPane;
  // End of variables declaration//GEN-END:variables
  JPanel movingPanel = new JPanel();
  boolean newTabCreated = false;
  Dimension theOnlyPaneD = new Dimension(289, 216);
}
